package com.wf.classRoomTest;

import com.wf.day_0531.test2.Person;

import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author mpk
 * @since 2024/6/3 10:26:28
 */
public class SetDemo {

    public static void main(String[] args) {

        HashSet<Person> hs = new HashSet<>();
        Person person = new Person("John", 19);
        Person person1 = new Person("John", 19);
        Person person2 = new Person("John", 1129);

        Collections.addAll(hs, person1, person2, person);




        // AtomicInteger sum = new AtomicInteger(0); // 使用 AtomicInteger 替代 Integer
        int[] sum = {0};
        hs.forEach(s -> {
            sum[0] += s.getAge();
            System.out.println(sum[0]); // 打印累加的总和
        });

        String s = " tertaa";

        Person person3 = new Person("John", 1);
        Person personc = new Person("John", 1);
        Person person5 = new Person("John", 1);
        Person person4 = new Person("John", 1);
        Person persona = new Person("John", 1);
        Person personq = new Person("John", 1);
        Person persone = new Person("John", 1);
        Person dpersonr = new Person("John", 1);


        extracted(person3,15);
        extracted(person5,15);
        extracted(dpersonr,15);
        extracted(personc,15);
        extracted(persona,15);
        extracted(person4,15);
        extracted(persone,15);
        extracted(personq,15);
        extracted(s);
        extracted("ceqwe");
        extracted("bbeqweqw");
        extracted("aa");
        extracted("dd");


        Person[] p = {

                new Person("John", 29),
                new Person("John", 29),
                new Person("yuekai", 15),
                new Person("honglian", 16),

        };
        Set<Person> collect = Stream.of(p)

                .collect(Collectors.toSet());

        Object[] array = collect.toArray();

        p = Arrays.copyOf(array, array.length, Person[].class);

        System.out.println(Arrays.toString(p));

        HashMap<Object, Object> objectObjectHashMap = new HashMap<>();

        objectObjectHashMap.put(1,2);


    }

    private static void extracted(String s) {

        /*int h = s.hashCode()) ^ (h >>> 16);*/

        // (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
    /*    static final int hash(Object key) {
            int h;
            return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
        }*/

        int h;
        int hash = (s == null) ? 0 : (h = s.hashCode()) ^ (h >>> 16);

        System.out.println((15 - 1) & hash);
    }
    private static void extracted(Person s,int index) {

        /*int h = s.hashCode()) ^ (h >>> 16);*/

        // (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
    /*    static final int hash(Object key) {
            int h;
            return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
        }*/

        int h;
        int hash = (s == null) ? 0 : (h = s.hashCode()) ^ (h >>> 16);

        System.out.println((index- 1) & hash);
    }


}
